/**
 * Created by hui on 16/7/30.
 */
var button = $('button');
var productID = $('.productID');
/*for (var i = 0;i<button.length;i++){
    button.eq(i).on('click',function (i) {
        productID.eq(i).css('display','table-row');
    })
}*/
for (var i = 0;i<button.length;i++){
    buttonClick(i);
}
function buttonClick(i) {
    button.eq(i).on('click',function () {
        if(button.eq(i).val() == 0){
            button.eq(i).val('1');
            button.eq(i).html('点击隐藏');
            productID.eq(i).show(200);
        }else {
            button.eq(i).val('0');
            button.eq(i).html('点击展开');
            productID.eq(i).hide(200);
        }
    })
}

$(function () {
    $('#submit').on('click', function submit() {
        var url = "edit_submit.html";
        $.ajax({
            type: "POST",
            url: url,
            data: {
                'Mobile': $('#mobile').val(),
                'Email': $('#email').val(),
                'QQ': $('#qq').val(),
                'Birthday': $('#birthday').val(),
                'Age': $('#age').val(),
                'Sex' : $('#sex').val()
            },
            success: function (msg) {
                $('#ps').val(msg);
            }
        })

    });
});

function feta_day(){
    var birthday = $('#birthday').val().match(/^(\d{1,4})-(\d{1,2})-(\d{1,2})$/);
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    var age = '';
    if (year >= birthday[1]) {
        if (month <= birthday[2]) {
            if (day >= birthday[3]) {
                age = year - birthday[1];
            } else {
                age = year - birthday[1] - 1;
            }
        } else {
            age = year - birthday[1];
        }
    } else {
        age = '请输入有效的出生日期';
    }
    if(age == -1){
        age = '请输入有效的出生日期';
    }
    return age;
}
jeDate({
    dateCell: "#birthday",
    format: "YYYY-MM-DD",
    isTime: false,
    minDate: "1900-01-01 00:00:00",
    choosefun: function () {
        var age = feta_day();
        $('#age').val(age);
    },
    okfun: function () {
        var age = feta_day();
        $('#age').val(age);
    }
});
var start = {
    dateCell: '#start_date',
    format: 'YYYY-MM-DD',
    minDate: '1900-01-01 00:00:00',
    maxDate: '2099-06-16 23:59:59', //最大日期
    choosefun: function(datas){
        end.minDate = datas.value; //开始日选好后，重置结束日的最小日期
    }
};
var end = {
    dateCell: '#end_date',
    format: 'YYYY-MM-DD',
    minDate: '1900-01-01 00:00:00',
    maxDate: '2099-06-16 23:59:59', //最大日期
    choosefun: function(datas){
        start.maxDate = datas.value; //将结束日的初始值设定为开始日的最大日期
    }
};
jeDate(start);
jeDate(end);

